
Code 
Wavelet analysis 

/* The implementation of an algorithm for calculating generalized spectral coefficients by wavelet analysis using Kravwtchouk functions with p=0.5 as the mother wavelets  */

char *m8[9]={"k4-4d","k8-4d","k16-4d","k32-4d","k64-4d","k128-4d","k256-4d","k512-4d","k1024-4d"};

union {
  char v[4*M];
  float p[M];
      }kr;


/*---open file "*.dat"-data file ------*/

_outtext(" name of data File?=           ");
   gets(jp);

if((f2=fopen(jp,"rt"))==0)
      printf("error-open file %s",jp);

for(j=0;j<1024;j++)
 fscanf(f2,"%d",&y[j]);

if((fclose(f2))!=0)
      {
      printf("error-close file %s",jp);
       exit(1);
       }

for(j1=2;j1<11;j1++){       /* start of window 2 pow j1 */

n=j1;
t1=pow(2.0,n);
m1=4*t1;
tm=4;  /* number of Krawtchouk functions  */


strcat(namef1,m8[n-2]);
 
/* open file "kr?d"- opening a file of calculated in advance values of the Krawtchouk functions of the length of 2 to degree n  */

if((f5=open(namef1,O_RDONLY|O_BINARY))==-1)

     q1=16*m1;
     q2=lseek(f5,q1,SEEK_CUR); /* we read Krawtchouk functions with p=0.5 */

for(j=0;j<4;j++){  /* cycle by Krawtchouk function number */
	      read(f5,kr.v,m1);
          for(i=0;i<t1;i++){
	     i3=fmod(i+t1*0.5,t1);
	     q[j][i]=kr.p[i3];
	     	     }/* read Krawtchouk functions */
	       }

an=pow(2,10-j1);
for(a=0;a<an;a++){   /* start shift the window */

for(j=0;j<tm;j++){

cq[0][j]=y[0+t1*a]*q[0][j];

for(i=1;i<t1;i++){ /* scalar product  */
cq[i][j]=cq[i-1][j]+y[i+t1*a]*q[i][j];
}

}

norm=0;
for(j=0;j<tm;j++){
norm=norm+pow(cq[i-1][j],2);
}

for(j2=0;j2<t1;j2++){
f[j2+t1*a][j1-2]=norm;
}


} /* close a - shift of the window  */

} /* close j1 - pow of 2*/


}

